package test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import service.MyService;
import dao.IDepositDao;
import dao.IStoreDao;
import dao.IUserDao;
import dao.entity.Deposit;
import dao.entity.Store;
import dao.entity.User;

public class Main {

    public static void main(String arg[]) {

        ApplicationContext context = new ClassPathXmlApplicationContext("springContext.xml");

        IUserDao userDao = (IUserDao) context.getBean("userDaoImpl");
        IStoreDao storeDao = (IStoreDao) context.getBean("storeDaoImpl");
        IDepositDao depositDao = (IDepositDao) context.getBean("depositDaoImpl");

        User user = new User();
        user.setName("Artiom");
        userDao.save(user);

        Store store = new Store();
        store.setName("Store 1");
        storeDao.save(store);

        Deposit deposit = new Deposit();
        deposit.setName("Deposit 1");
        deposit.getStores().add(store);
        depositDao.save(deposit);

        store.getDeposits().add(deposit);
        storeDao.saveOrUpdate(store);

        MyService service = (MyService) context.getBean("myService");
        service.doSmth();
    }

}
